<?php
class Admin_news extends Controller
{
	function Admin_news()
	{
		parent::Controller();
	}
	function listnews(){
		$page_num = '10';//每页的数据
		$ab=$this->uri->segment(3)?$this->uri->segment(3):1;
		$total_nums=$this->commonmodel->nums('gaoji_news');//这里得到从数据库中的总页数
		$data['query']=$this->commonmodel->sql_self("SELECT gaoji_news.* ,gaoji_newsort.title as b FROM gaoji_news,gaoji_newsort WHERE gaoji_news.sortid=gaoji_newsort.sortid  order by b desc limit $ab,$page_num");
		$this->load->library('pagination');
		$config['base_url'] = $this->config->item('base_url').'/index.php/admin_news/listnews/';
		$config['total_rows'] = $total_nums;//总共多少条数据
		$config['per_page'] = $page_num;//每页显示几条数据
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$config['first_link'] = '首页';
		$config['first_tag_open'] = '<li>';//“第一页”链接的打开标签。
		$config['first_tag_close'] = '</li>';//“第一页”链接的关闭标签。
		$config['last_link'] = '尾页';//你希望在分页的右边显示“最后一页”链接的名字。
		$config['last_tag_open'] = '<li>';//“最后一页”链接的打开标签。
		$config['last_tag_close'] = '</li>';//“最后一页”链接的关闭标签。
		$config['next_link'] = '下一页';//你希望在分页中显示“下一页”链接的名字。
		$config['next_tag_open'] = '<li>';//“下一页”链接的打开标签。
		$config['next_tag_close'] = '</li>';//“下一页”链接的关闭标签。
		$config['prev_link'] = '上一页';//你希望在分页中显示“上一页”链接的名字。
		$config['prev_tag_open'] = '<li>';//“上一页”链接的打开标签。
		$config['prev_tag_close'] = '</li>';//“上一页”链接的关闭标签。
		$config['cur_tag_open'] = '<li class="current">';//“当前页”链接的打开标签。
		$config['cur_tag_close'] = '</li>';//“当前页”链接的关闭标签。
		$config['num_tag_open'] = '<li>';//“数字”链接的打开标签。
		$config['num_tag_close'] = '</li>';
		$this->pagination->initialize($config);
		$this->load->view('admin_listnews',$data);
	}
	/*
	function listnews()
	{
		$page_num = '10';//每页的数据
		$data= $this->commonmodel->page('gaoji_news',$page_num,$this->uri->segment(3));
		$total_nums=$this->commonmodel->nums('gaoji_news');//这里得到从数据库中的总页数
		$data['query']=$data[0];//把查询结果放到$data['query']中
		$this->load->library('pagination');
		$config['base_url'] = $this->config->item('base_url').'/index.php/admin_news/listnews/';
		$config['total_rows'] = $total_nums;//总共多少条数据
		$config['per_page'] = $page_num;//每页显示几条数据
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$config['first_link'] = '首页';
		$config['first_tag_open'] = '<li>';//“第一页”链接的打开标签。
		$config['first_tag_close'] = '</li>';//“第一页”链接的关闭标签。
		$config['last_link'] = '尾页';//你希望在分页的右边显示“最后一页”链接的名字。
		$config['last_tag_open'] = '<li>';//“最后一页”链接的打开标签。
		$config['last_tag_close'] = '</li>';//“最后一页”链接的关闭标签。
		$config['next_link'] = '下一页';//你希望在分页中显示“下一页”链接的名字。
		$config['next_tag_open'] = '<li>';//“下一页”链接的打开标签。
		$config['next_tag_close'] = '</li>';//“下一页”链接的关闭标签。
		$config['prev_link'] = '上一页';//你希望在分页中显示“上一页”链接的名字。
		$config['prev_tag_open'] = '<li>';//“上一页”链接的打开标签。
		$config['prev_tag_close'] = '</li>';//“上一页”链接的关闭标签。
		$config['cur_tag_open'] = '<li class="current">';//“当前页”链接的打开标签。
		$config['cur_tag_close'] = '</li>';//“当前页”链接的关闭标签。
		$config['num_tag_open'] = '<li>';//“数字”链接的打开标签。
		$config['num_tag_close'] = '</li>';
		$this->pagination->initialize($config);
		$this->load->view('admin_listnews',$data);
	}
	*/
	function addnews(){
		$data=$this->commonmodel->getsort('gaoji_newsort');
		$getchild=$this->commonmodel->getchildren($data,0,0);
		$data['child']=$getchild;
		$this->load->view('admin_addnews',$data);
	}
	function insertnews(){
		//print_r($_POST);exit;
		//print_r($_POST);exit;
		$this->commonmodel->insert('gaoji_news',$_POST);
		echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
		echo "<script language='JavaScript'>alert('添加成功');</script>";
		redirect('/admin_news/addnews','refresh');
	}
	function updatenewsindex(){
		$data=$this->commonmodel->getsort('gaoji_newsort');
		$getchild=$this->commonmodel->getchildren($data,0,0);
		$data['child']=$getchild;
		$data['query']=$this->commonmodel->get_where('gaoji_news','newsid',$this->uri->segment(3));
		$this->load->view('admin_updatenews',$data);
	}
	
	function updatenews(){
		$newsid=$_POST['newsid'];
		unset($_POST['newsid']);
		$this->commonmodel->update('gaoji_news',$_POST,'newsid',$newsid);
	    echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
		echo "<script language='JavaScript'>alert('更新成功');</script>";
		
	}
	function sortnews(){
		$data=$this->commonmodel->getsort('gaoji_newsort');
		$getchild=$this->commonmodel->getchildren($data,0,0);
		$data['child']=$getchild;
		$this->load->view('admin_sortnews',$data);
	}
	function delete(){
		$this->commonmodel->delete('gaoji_news','newsid',$this->uri->segment(3));
		redirect('/admin_news/listnews','refresh');
	}
}

?>